import React from 'react';
import {inject, observer} from 'mobx-react';
import {Row, Col} from 'antd';
import {WeaCheckbox, WeaSearchGroup, WeaBrowser,WeaLocaleProvider} from 'ecCom';
const toJS = mobx.toJS;
const getLabel = WeaLocaleProvider.getLabel;
@inject ('planBaseStore')
@observer
export default class OtherInfoSearchGroup extends React.Component {
  constructor (props) {
    super (props);
    this.state = {};
    this.store = this.props.planBaseStore;
  }

  makeWeaBrowser = (
    ids,
    names,
    type,
    inputStyle,
    formParamName,
    namesName,
    isSingle,
    title
  ) => {
    const {canedit} = this.store;
    let replaceDatas = [];
    if (ids) {
      let idArray = ids.split (',');
      let nameArray = names.split (' ');
      for (let index = 0; index < idArray.length; index++) {
        replaceDatas.push ({id: idArray[index], name: nameArray[index]});
      }
    }
    return (
      <WeaBrowser
        viewAttr={canedit ? 2 : 1}
        replaceDatas={replaceDatas}
        type={type}
        title={title}
        isSingle={isSingle}
        inputStyle={inputStyle}
        onChange={(ids, names, datas) =>
          this.browserOnChange (ids, names, datas, formParamName, namesName)}
      />
    );
  };

  getParamSetter = () => {
    const {planBaseStore} = this.props;
    const {setFormParams} = planBaseStore;
    return setFormParams;
  };

  browserOnChange = (ids, names, datas, idsName, namesName) => {
    var reg = new RegExp (',', 'g');
    names = names.replace (reg, ' ');
    const setFormParams = this.getParamSetter ();
    setFormParams (idsName, ids);
    setFormParams (namesName, names);
  };

  getConfigCheckBox = (v, id, className, content, paramName, display) => {
    const {planBaseStore} = this.props;
    const {setFormParams} = planBaseStore;
    const {canedit} = this.store;
    return (
      <WeaCheckbox
        viewAttr={canedit ? 2 : 1}
        value={v}
        id={id}
        display={display}
        className={className}
        content={content}
        onChange={e => {
          setFormParams (paramName, e);
        }}
      />
    );
  };
  setEmptyDate(datas){
    const {planBaseStore} = this.props;
    planBaseStore.emptydata = datas;
  }
  render () {
    const {planBaseStore} = this.props;
    let {setFormParams,loading, canedit,formParams, tableDataList,emptydata,canfresh} = planBaseStore;
    let {resourceid, resourcetype} = planBaseStore.treeNodeData;
    let applyOtherTitle = '';
    if (resourcetype == '4') {
      applyOtherTitle = getLabel('30042','人员') ;
    } else if (resourcetype == '3') {
      applyOtherTitle = getLabel('27511','部门') ;
    } else if (resourcetype == '2'){
      applyOtherTitle = getLabel('33553','分部');
    }
    return (
      <div className="wea-workrelate-plan-base-otherinfo">
        <WeaSearchGroup title={getLabel('16169','其他信息') } showGroup={true}>
          <div className="workrelate-plan-base-div">
          <Row gutter="2" className="workrelate-plan-base-row">
            <Col span={4}><span className="col-title">{getLabel('508949','报告模版制定人') }</span></Col>
            <Col span={8}>
              {' '}
              {this.makeWeaBrowser (
                formParams.programcreate,
                formParams.programcreatename,
                17,
                {},
                'programcreate',
                'programcreatename',
                false,
                getLabel('508949','报告模版制定人')
              )}
            </Col>
            <Col span={4}><span className="col-title">{getLabel('508950','报告审批人')}</span></Col>
            <Col span={4}>
              {this.makeWeaBrowser (
                formParams.reportaudit,
                formParams.reportauditname,
                17,
                {},
                'reportaudit',
                'reportauditname',
                false,
                getLabel('508950','报告审批人')
              )}

            </Col>
            <Col span={4}>
              <div className="workrelate-plan-base-checkbox-div">
                {this.getConfigCheckBox (
                  formParams.manageraudit + '',
                  'sp',
                  'manager-check-box',
                  getLabel('508911','直接上级审批'),
                  'manageraudit'
                )}
              </div>
            </Col>
          </Row>
          <Row gutter="2" className="workrelate-plan-base-row">
            <Col span={4}><span className="col-title">{getLabel('508960','报告查看人')}</span></Col>
            <Col span={8}>
              {this.makeWeaBrowser (
                formParams.reportview,
                formParams.reportviewname,
                17,
                {},
                'reportview',
                'reportviewname',
                false,
                getLabel('508960','报告查看人')
              )}
            </Col>
            <Col span={4}><span className="col-title">{getLabel('22210','附件上传目录') }</span></Col>
            <Col span={8}>
              {this.makeWeaBrowser (
                formParams.docsecid,
                formParams.docpath,
                'doccategory',
                {},
                'docsecid',
                'docpath',
                false,
                getLabel('22210','附件上传目录') 
              )}
            </Col>
          </Row>
          <Row gutter="2" className="workrelate-plan-base-row">
            <Col span={4}><span className="col-title">{getLabel('508961','上级定义模板') }</span></Col>
            <Col span={8}>
              {this.getConfigCheckBox (
                formParams.ismanager + '',
                'f1',
                'switch-check-box',
                '',
                'ismanager',
                'switch'
              )}
            </Col>
            <Col span={4}><span className="col-title">{getLabel('508962','个人定义模板')}</span></Col>
            <Col span={8}>
              {this.getConfigCheckBox (
                formParams.isself + '',
                'f2',
                'switch-check-box',
                '',
                'isself',
                'switch'
              )}
            </Col>
          </Row>
          {canedit && resourcetype!=1 && <Row gutter="2" className="workrelate-plan-base-row">
            <Col span={4}>
              <span className="col-title">{ getLabel('508963','应用到其他$code$').replace("$code$",applyOtherTitle)}</span>
            </Col>
            <Col span={8}>
              {canfresh && resourcetype == 2 &&
                <WeaBrowser
                  title={getLabel('508921','应用到其他分部') }
                  viewAttr={2}
                  replaceDatas={emptydata}
                  type={194}
                  isSingle={false}
                  onChange={(ids, names, datas) => {
                    setFormParams ('subcompanyids', ids);
                    this.setEmptyDate(datas);
                  }}
                />}
              {canfresh && resourcetype == 3 &&
                <WeaBrowser
                title={getLabel('508920','应用到其他部门') }
                  viewAttr={2}
                  replaceDatas={emptydata}
                  type={57}
                  isSingle={false}
                  onChange={(ids, names, datas) => {
                    setFormParams ('departmentids', ids);
                    this.setEmptyDate(ids, names);
                  }
                  }
                />}
              {canfresh && resourcetype == 4 &&
                <WeaBrowser
                title={getLabel('508968','应用到其他员工') }
                  viewAttr={2}
                  replaceDatas={emptydata}
                  type={17}
                  isSingle={false}
                  onChange={(ids, names, datas) => {
                    setFormParams ('resourceids', ids);
                    this.setEmptyDate(datas);
                  }}
                />}
            </Col>
          </Row>}
          </div>
        </WeaSearchGroup>
      </div>
    );
  }
}
